use "C:\Users\Patrick Shea\Dropbox\My Projects\Default and Heirachy\Empirical Analysis\Data\JCR_replication.dta", clear


*****************************
**Table 1
*********************************

***US SUPPORT AND DEFAULT***

*MODEL 1: BASELINE 
logit rescase usa_median i.ccode if oecd!=1, cluster(ccode)
estimates store c1

*MODEL 2: MAIN 
logit rescase usa_median imfcredit rightlead lngdppc_wdi lngdp_wdi lntrade_wdi debtGDP ny_gdp_totl_rt_zs v2x_polyarchy ryrs r2 r3 i.ccode if oecd!=1, cluster(ccode)
estimates store c2

hist usa_median if e(sample), freq scheme(s1mono)
graph hbox usa_median if e(sample), over(ccode) scheme(s1mono)

*graphing purposes
xtreg rescase usa_median imfcredit rightlead lngdppc_wdi lngdp_wdi lntrade_wdi debtGDP ny_gdp_totl_rt_zs v2x_polyarchy ryrs r2 r3 if oecd!=1,  fe

margins , at( usa_median =(-0.9(.1)2.7)) atmeans

	marginsplot, recast(line) recastci(rarea) /// 
    graphregion(color(white)) /// 
    l1title("Probability of Restructuring") ///
    xtitle("US Support") /// 
    title("") /// 
    subtitle("") /// 
    note("") /// 
    addplot(histogram usa_median if e(sample), freq  /// 
        fcolor(navy%20) lcolor(navy%0) yaxis(2)) /// 
			ytitle("", axis(1)) /// 
    legend(off) ///    
    scheme(s1mono) name(res, replace)
	
	gr_edit yaxis2.draw_view.setstyle, style(no)




*MODEL 3: DEFAULT BASELINE 
logit default3 usa_median i.ccode if oecd!=1, cluster(ccode)
estimates store c3

*MODEL 4: DEFAULT CONTROLS 
logit default3 usa_median  imfcredit rightlead lngdppc_wdi lngdp_wdi lntrade_wdi debtGDP ny_gdp_totl_rt_zs v2x_polyarchy  ryrs r2 r3 i.ccode if oecd!=1, cluster(ccode) 
estimates store c4

*graphing purposes
xtreg default3 usa_median  imfcredit rightlead lngdppc_wdi lngdp_wdi lntrade_wdi debtGDP ny_gdp_totl_rt_zs v2x_polyarchy ryrs r2 r3  if oecd!=1, fe

margins , at( usa_median =(-0.9(.1)2.7)) atmeans


	
	
	marginsplot, recast(line) recastci(rarea) /// 
    graphregion(color(white)) /// 
    l1title("Probability of Default") ///
    xtitle("US Support") /// 
    title("") /// 
    subtitle("") /// 
    note("") /// 
    addplot(histogram usa_median if e(sample), freq  /// 
        fcolor(navy%20) lcolor(navy%0) yaxis(2)) /// 
			ytitle("", axis(1)) /// 
    legend(off) ///    
    scheme(s1mono) name(default, replace)
	
	gr_edit yaxis2.draw_view.setstyle, style(no)
	
	
	
graph combine res default, ycommon


*graph export "C:\Users\Patrick Shea\Dropbox\My Projects\Default and Heirachy\Manuscript\fig1.jpg", as(jpg) name("Graph") quality(90) replace
*graph export "C:\Users\Patrick Shea\Dropbox\My Projects\Default and Heirachy\Manuscript\fig1.pdf", as(pdf) name("Graph")  replace



estout c1 c2 c3 c4, cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) starlevels(* 0.10 ** 0.05) ///
stats(ll N r2, fmt(%9.2f %9.0f) labels("Log-Like" ))  style(tex) ///
legend label collabels(none) varlabels(_cons Constant) ///
order(usa_median) drop(r2 r3 *ccode ) ///
mlabels ("Baseline" "Controls" "Default" "Default Controls") ///
title("US Support and the Probability of Restructuring") 


*****************************
**Table 2
*********************************

stset wanted, id(ccode)  failure(anyissue==1)

gen ushi = 0 if usa_median !=. 
sum usa_median
replace  ushi= 1 if usa_median >0& usa_median!=. 


sts test ushi, logrank
sts graph, by(ushi)  graphregion(color(white)) bgcolor(white) xtitle("Analysis Time") ///
legend(label(1 "Low US Support") label(2 "High US Support")) 
sts, hazard  by(ushi) kernel(gaussian) graphregion(color(white)) bgcolor(white) xtitle("Analysis Time") ///
legend(label(1 "Low US Support") label(2 "High US Support")) 

*MODEL 1: BASELINE
stcox usa_median, nohr cluster(ccode)
estimates store cox3

*MODEL 2: CONTROLS
stcox usa_median imfcredit rightlead lngdppc_wdi lngdp_wdi lntrade_wdi debtGDP ny_gdp_totl_rt_zs v2x_polyarchy, nohr cluster(ccode)
estimates store cox1

lab var lastHC "Haircut Size"

*MODEL 3: CONTROLING FOR SIZE OF HAIRCUT
stset wanted, id(ccode) failure(anyissue==1)

stcox usa_median lastHC imfcredit rightlead lngdppc_wdi lngdp_wdi lntrade_wdi debtGDP ny_gdp_totl_rt_zs v2x_polyarchy , nohr cluster(ccode)
estimates store cox2

 estout cox3 cox1 cox2, cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) starlevels(* 0.10 ** 0.05) ///
stats(ll N, fmt(%9.2f %9.0f) labels("Log-Like" ))  style(tex) ///
legend label collabels(none) varlabels(_cons Constant) ///
order(usa_median lastHC) drop() ///
mlabels ("Baseline" "Controls" "Haircut") ///
title("") 











**********************************************************
**Table 3
***********************************************************

xtset ccode year

 gen yr08 = (year==2008 |year==2009)
 
*MODEL 1: FULL SAMPLE 
xtreg annualJPspread    c.usa_median imfcredit  rightlead ///
lngdppc_wdi lngdp_wdi lntrade_wdi debtGDP v2x_polyarchy   ny_gdp_totl_rt_zs yr08 , i(ccode) fe 
estimates store s1

*MODEL 2: POST RESTRUCTURE 
xtreg annualJPspread    usa_median imfcredit  rightlead ///
 lngdppc_wdi lngdp_wdi lntrade_wdi debtGDP v2x_polyarchy ///
 ny_gdp_totl_rt_zs yr08 ///
 if restruct_ongoing!=1 & yrsHC3>=1 & yrsHC!=. , i(ccode) fe 
 estimates store s2
 
 **standardized US support
  *xtreg annualJPspread    std_usa_median ///
 *lngdppc_wdi lngdp_wdi lntrade_wdi v2x_polyarchy   ny_gdp_totl_rt_zs yr08 if restruct_ongoing!=1 & yrsHC>=1 & yrsHC!=. , i(ccode) fe

 
 *MODEL 3: YEARS 1-7
xtreg annualJPspread    usa_median imfcredit  rightlead ///
lngdppc_wdi lngdp_wdi lntrade_wdi v2x_polyarchy debtGDP  ny_gdp_totl_rt_zs yr08 if restruct_ongoing!=1 & yrsHC>=1 & yrsHC <8 , i(ccode) fe 
estimates store s3
  
lab var yr08 "Great Recession"

gen i = FEDFUNDS*Echelon2
	tab year, g(yr_)


xtivreg2 annualJPspread lngdppc_wdi imfcredit  rightlead lngdp_wdi lntrade_wdi debtGDP v2x_polyarchy   ny_gdp_totl_rt_zs yr08 (usa_median = i FEDFUNDS  Echelon2 yr_*) if oecd!=1 , fe first gmm
estimates store iv1


xtivreg2 annualJPspread lngdppc_wdi imfcredit  rightlead lngdp_wdi lntrade_wdi debtGDP v2x_polyarchy   ny_gdp_totl_rt_zs yr08 (usa_median = i FEDFUNDS  Echelon2 yr_*) if oecd!=1 & restruct_ongoing!=1 & yrsHC3>=1 & yrsHC!=., fe first gmm
estimates store iv2

xtivreg2 annualJPspread lngdppc_wdi imfcredit  rightlead lngdp_wdi lntrade_wdi debtGDP v2x_polyarchy   ny_gdp_totl_rt_zs yr08 (usa_median = i FEDFUNDS  Echelon2 yr_*) if oecd!=1 & restruct_ongoing!=1 & yrsHC>=1 & yrsHC <8 , fe first gmm
estimates store iv3




 
estout s1 s2 s3 iv1 iv2 iv3,  cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) starlevels(* 0.1 ** 0.05 )  ///
stats(r2 N, fmt(%9.2f %9.0f) labels("R2"))  style(tex) ///
legend label collabels(none) varlabels(_cons Constant) ///
order(usa_median) drop(_cons) ///
mlabels ("Full Sample" "Post-Restructure" "Post Restructure (1-7)") ///
title("") 

**First Stage 

tab ccode, g(cc_)


  cmp (annualJPspread = usa_median lngdppc_wdi imfcredit  rightlead lngdp_wdi lntrade_wdi debtGDP v2x_polyarchy   ny_gdp_totl_rt_zs yr08 cc_*) ///
 (usa_median = i FEDFUNDS  Echelon2 cc_* yr_* lngdppc_wdi imfcredit  rightlead lngdp_wdi lntrade_wdi debtGDP v2x_polyarchy   ny_gdp_totl_rt_zs) if oecd!=1  ///
, ind($cmp_cont $cmp_cont) tech(dfp nr)  diff robust
estimates store iv1a

  cmp (annualJPspread = usa_median lngdppc_wdi imfcredit  rightlead lngdp_wdi lntrade_wdi debtGDP v2x_polyarchy   ny_gdp_totl_rt_zs yr08 cc_*) ///
 (usa_median = i FEDFUNDS  Echelon2 cc_* yr_* lngdppc_wdi imfcredit  rightlead lngdp_wdi lntrade_wdi debtGDP v2x_polyarchy   ny_gdp_totl_rt_zs) if oecd!=1 & restruct_ongoing!=1 & yrsHC3>=1 & yrsHC!=. ///
, ind($cmp_cont $cmp_cont) tech(dfp nr)  diff robust
estimates store iv2a


  cmp (annualJPspread = usa_median lngdppc_wdi imfcredit  rightlead lngdp_wdi lntrade_wdi debtGDP v2x_polyarchy   ny_gdp_totl_rt_zs yr08 cc_*) ///
 (usa_median = i FEDFUNDS  Echelon2 cc_* yr_* lngdppc_wdi imfcredit  rightlead lngdp_wdi lntrade_wdi debtGDP v2x_polyarchy   ny_gdp_totl_rt_zs) if oecd!=1 & restruct_ongoing!=1 & yrsHC>=1 & yrsHC <8 ///
, ind($cmp_cont $cmp_cont) tech(dfp nr)  diff robust
estimates store iv3a

estout s1 s2 s3 iv1a iv2a iv3a, cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) starlevels(* 0.1 ** 0.05 )  ///
stats(r2 N, fmt(%9.2f %9.0f) labels("R2"))  style(tex) ///
legend label collabels(none) varlabels(_cons Constant) ///
order(usa_median) drop(_cons cc_* yr_*) ///
mlabels ("Full Sample" "Post-Restructure" "Post Restructure (1-7)") ///
title("") 

**********************************************************
**Table 4 Components 
***********************************************************
global cntl imfcredit rightlead lngdppc_wdi lngdp_wdi lntrade_wdi debtGDP ny_gdp_totl_rt_zs v2x_polyarchy ryrs r2 r3

logit rescase log_us_arms us_ex us_pact log_us_troops us_vis log_us_words $cntl i.ccode if oecd!=1, cluster(ccode)
estimates store c8

logit default3 log_us_arms us_ex us_pact log_us_troops us_vis log_us_words $cntl i.ccode if oecd!=1, cluster(ccode)
estimates store c8a

stset wanted, id(ccode)  failure(anyissue==1)

stcox log_us_arms us_ex us_pact log_us_troops us_vis log_us_words imfcredit rightlead lngdppc_wdi v2x_polyarchy, nohr cluster(ccode)

estimates store s8


xtreg annualJPspread  log_us_arms us_ex us_pact log_us_troops us_vis log_us_words imfcredit  rightlead ///
lngdppc_wdi lngdp_wdi lntrade_wdi debtGDP v2x_polyarchy   ny_gdp_totl_rt_zs yr08 , i(ccode) fe 
estimates store b7


xtreg annualJPspread  log_us_arms us_ex us_pact log_us_troops us_vis log_us_words imfcredit  rightlead ///
lngdppc_wdi lngdp_wdi lntrade_wdi debtGDP v2x_polyarchy   ny_gdp_totl_rt_zs yr08 if oecd!=1 & restruct_ongoing!=1 & yrsHC3>=1 & yrsHC!=., i(ccode) fe 
estimates store b8


xtreg annualJPspread  log_us_arms us_ex us_pact log_us_troops us_vis log_us_words imfcredit  rightlead ///
lngdppc_wdi lngdp_wdi lntrade_wdi debtGDP v2x_polyarchy   ny_gdp_totl_rt_zs yr08 if oecd!=1 & restruct_ongoing!=1 & yrsHC>=1 & yrsHC <8 , i(ccode) fe 
estimates store b9

lab var log_us_arms "log US Arms"
lab var us_ex "US Exercise"
lab var us_pact "US Pact"
lab var log_us_troops "log US troops"
lab var  us_vis "US Visit"
lab var  log_us_words "log US Words"


estout c8 c8a s8 b7 b8 b9, cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) starlevels(* 0.10 ** 0.05) ///
stats(ll r2 N, fmt(%9.2f %9.2f %9.0f )  labels("Log-Like" ))  style(tex) ///
legend label collabels(none) varlabels(_cons Constant) ///
order(log_us_arms us_ex us_pact log_us_troops us_vis log_us_words) drop(r2 r3 *ccode ) 





**********************************************************
**Table 4 Components 
***********************************************************



global cntl imfcredit rightlead lngdppc_wdi lngdp_wdi lntrade_wdi debtGDP ny_gdp_totl_rt_zs v2x_polyarchy

stset wanted, id(ccode)  failure(anyissue==1)

stcox log_us_arms  $cntl, nohr cluster(ccode)

estimates store s1

stcox  us_ex  $cntl, nohr cluster(ccode)

estimates store s2
stcox us_pact  $cntl, nohr cluster(ccode)

estimates store s3

stcox log_us_troops $cntl, nohr cluster(ccode)

estimates store s4
stcox us_vis $cntl, nohr cluster(ccode)

estimates store s5
stcox log_us_words $cntl, nohr cluster(ccode)

estimates store s6


stcox log_us_arms us_ex us_pact us_troops us_vis log_us_words $cntl, nohr cluster(ccode)

estimates store s8

stcox log_us_arms us_ex us_pact log_us_troops us_vis log_us_words lastHC, nohr cluster(ccode)

estimates store s9

stcox log_us_arms us_ex us_pact  log_us_words, nohr cluster(ccode)

estimates store s8a

stcox log_us_arms us_ex us_pact log_us_words lastHC, nohr cluster(ccode)

estimates store s9a


 estout s1 s2 s3 s3 s4 s5 s6 s8 s9, cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) starlevels(* 0.10 ** 0.05) ///
stats(ll N, fmt(%9.2f %9.0f) labels("Log-Like" ))  style(tex) ///
legend label collabels(none) varlabels(_cons Constant) ///
order(log_us_arms us_ex us_pact log_us_troops us_vis log_us_words lastHC lastHC) drop() ///
mlabels ("Baseline" "Controls" "Haircut") ///
title("") 

xtset ccode year
cap drop yr08
 gen yr08 = (year==2008 |year==2009)


xtreg annualJPspread  log_us_arms imfcredit  rightlead ///
lngdppc_wdi lngdp_wdi lntrade_wdi debtGDP v2x_polyarchy   ny_gdp_totl_rt_zs yr08 , i(ccode) fe 
estimates store b1

xtreg annualJPspread   us_ex imfcredit  rightlead ///
lngdppc_wdi lngdp_wdi lntrade_wdi debtGDP v2x_polyarchy   ny_gdp_totl_rt_zs yr08 , i(ccode) fe 
estimates store b2


xtreg annualJPspread   us_pact imfcredit  rightlead ///
lngdppc_wdi lngdp_wdi lntrade_wdi debtGDP v2x_polyarchy   ny_gdp_totl_rt_zs yr08 , i(ccode) fe 
estimates store b3


xtreg annualJPspread  log_us_troops imfcredit  rightlead ///
lngdppc_wdi lngdp_wdi lntrade_wdi debtGDP v2x_polyarchy   ny_gdp_totl_rt_zs yr08 , i(ccode) fe 
estimates store b4


xtreg annualJPspread  us_vis imfcredit  rightlead ///
lngdppc_wdi lngdp_wdi lntrade_wdi debtGDP v2x_polyarchy   ny_gdp_totl_rt_zs yr08 , i(ccode) fe 
estimates store b5


xtreg annualJPspread  log_us_words imfcredit  rightlead ///
lngdppc_wdi lngdp_wdi lntrade_wdi debtGDP v2x_polyarchy   ny_gdp_totl_rt_zs yr08 , i(ccode) fe 
estimates store b6

xtreg annualJPspread  log_us_arms us_ex us_pact log_us_troops us_vis log_us_words imfcredit  rightlead ///
lngdppc_wdi lngdp_wdi lntrade_wdi debtGDP v2x_polyarchy   ny_gdp_totl_rt_zs yr08 , i(ccode) fe 
estimates store b7


estout b1 b2 b3 b4 b5 b6 b7, cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) starlevels(* 0.05) ///
stats(ll N r2, fmt(%9.2f %9.0f) labels("Log-Like" ))  style(tex) ///
legend label collabels(none) varlabels(_cons Constant) ///
order(log_us_arms us_ex us_pact log_us_troops us_vis log_us_words) drop() 


xtreg annualJPspread   c.us_vis##c.log_us_words  imfcredit  rightlead ///
lngdppc_wdi lngdp_wdi lntrade_wdi debtGDP v2x_polyarchy   ny_gdp_totl_rt_zs yr08 , i(ccode) fe 

xtreg annualJPspread   c.us_pact##c.log_us_words  imfcredit  rightlead ///
lngdppc_wdi lngdp_wdi lntrade_wdi debtGDP v2x_polyarchy   ny_gdp_totl_rt_zs yr08 , i(ccode) fe 


xtreg annualJPspread   c.log_us_troops##c.log_us_words  imfcredit  rightlead ///
lngdppc_wdi lngdp_wdi lntrade_wdi debtGDP v2x_polyarchy   ny_gdp_totl_rt_zs yr08 , i(ccode) fe 


